# Copyright (c) 2020 Presto Labs Pte. Ltd.
# Author: donggu

workspace(name = "coin")

# repo
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")


# pybind
http_archive(
    name = "pybind11",
    build_file = "@pybind11_bazel//:pybind11.BUILD",
    strip_prefix = "pybind11-2.10.3",
    urls = [
        "https://github.com/pybind/pybind11/archive/refs/tags/v2.10.3.tar.gz",
    ],
)

git_repository(
    name = "pybind11_bazel",
    commit = "faf56fb3df11287f26dbc66fdedf60a2fc2c6631",
    remote = "https://github.com/pybind/pybind11_bazel.git",
)

load("@pybind11_bazel//:python_configure.bzl", "python_configure")

python_configure(name = "local_config_python")

# ---------------------------------------------------------------------------- #
#                                    Protobuf                                  #
# ---------------------------------------------------------------------------- #

local_repository(
    name = "boringssl",
    path = "cc/third_party/boringssl_dummy",
)

http_archive(
    name = "com_google_protobuf",
    strip_prefix = "protobuf-3.21.11",
    urls = [
        "https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.21.11.tar.gz",
    ],
)
http_archive(
    name = "com_github_grpc_grpc",
    strip_prefix = "grpc-1.51.1",
    urls = [
        "https://github.com/grpc/grpc/archive/refs/tags/v1.51.1.tar.gz",
    ],
)

http_archive(
    name = "rules_proto_grpc",
    sha256 = "fb7fc7a3c19a92b2f15ed7c4ffb2983e956625c1436f57a3430b897ba9864059",
    strip_prefix = "rules_proto_grpc-4.3.0",
    urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/4.3.0.tar.gz"],
)

load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_toolchains", "rules_proto_grpc_repos")
rules_proto_grpc_toolchains()
rules_proto_grpc_repos()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()

# language
load("@rules_proto_grpc//cpp:repositories.bzl", rules_proto_grpc_cpp_repos = "cpp_repos")
rules_proto_grpc_cpp_repos()
load("@rules_proto_grpc//python:repositories.bzl", rules_proto_grpc_python_repos = "python_repos")
rules_proto_grpc_python_repos()
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
grpc_deps()
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
grpc_extra_deps()

# ---------------------------------------------------------------------------- #
#                                    Flatbuffers                               #
# ---------------------------------------------------------------------------- #

http_archive(
    name = "com_github_google_flatbuffers",
    sha256 = "4b8b21adbfe8a74b90604161afcf87c125a26b86c99327e7a04525080606536c",
    strip_prefix = "flatbuffers-1.12.0",
    urls = [
        "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/google/flatbuffers/archive/v1.12.0.zip",
        "https://github.com/google/flatbuffers/archive/v1.12.0.zip",
    ],
)

# ---------------------------------------------------------------------------- #
#                                  Bazel Tools                                 #
# ---------------------------------------------------------------------------- #

# generate compilation-database for clangd
http_archive(
    name = "com_grail_bazel_compdb",
    sha256 = "4ada65ea3652c016c164ea219d1860189fa30c0a100c79acb19c380a073a5384",
    strip_prefix = "bazel-compilation-database-ad537aaf7fa96ecbdb0f7e37b74f0d055f54dab7",
    urls = [
        "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/grailbio/bazel-compilation-database/archive/ad537aaf7fa96ecbdb0f7e37b74f0d055f54dab7.tar.gz",
        "https://github.com/grailbio/bazel-compilation-database/archive/ad537aaf7fa96ecbdb0f7e37b74f0d055f54dab7.tar.gz",
    ],
)

# ---------------------------------------------------------------------------- #
#                                     Nazel                                    #
# ---------------------------------------------------------------------------- #

local_repository(
    name = "nazel",
    path = "nazel",
)

load("@nazel//:repositories.bzl", "nazel_dependencies")

nazel_dependencies()

# -------------------------------------------------------------------------- #
#                                    Presto                                  #
# -------------------------------------------------------------------------- #

git_repository(
    name = "navi_third_party2",
    commit = "85c8a8a61a0d3012f4bc7aa19edc0e9fdce2ae10",
    remote = "git@github.com:prestolabs/navi_third_party2.git",
    shallow_since = "1607000000",
)

local_repository(
    name = "apiset",
    path = "external/apiset",
)

git_repository(
    name = "motion",
    commit = "4934c1e0b839d88d3a0c9b219844de7945cfee4d",
    remote = "git@github.com:prestolabs/motion_lib.git",
    shallow_since = "1607000000",
)

git_repository(
    name = "fastfeature",
    commit = "14784422a5c555b7dbbf3f30d034489012f10154",
    remote = "git@github.com:prestolabs/fastfeature.git",
    shallow_since = "1671369600",
    init_submodules = 0,
)

git_repository(
    name = "quickfix",
    commit = "6f0ea38bb7579faf77d4b7f672a4ed4bc77f7a48",
    remote = "git@github.com:prestolabs/quickfix.git",
    shallow_since = "1671519773 +0800",
)

git_repository(
    name = "nghttp2",
    commit = "74a4c4bd926fc813804c640a91001435756e0442",
    remote = "git@github.com:prestolabs/nghttp2.git",
    shallow_since = "1603265512 +0800",
)

git_repository(
    name = "starkware",
    commit = "d0e0275288098444c1fef8e4b6c07f505446d2eb",
    remote = "git@github.com:prestolabs/dydx_crypto.git",
    shallow_since = "1603265512 +0800",
)

# External dependency: Eigen
http_archive(
    name = "eigen",
    sha256 = "e09b89aae054e9778ee3f606192ee76d645eec82c402c01c648b1fe46b6b9857",
    strip_prefix = "eigen-3.3.7",
    urls = [
        "https://nexus-repo.corp.prestolabs.io/repository/gitlab-proxy/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip",
        "https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip",
    ],
    build_file_content =
"""
cc_library(
    name = 'eigen',
    srcs = [],
    includes = ['.'],
    hdrs = glob(['Eigen/**', 'unsupported/Eigen/**']),
    visibility = ['//visibility:public'],
)
"""
)

# External dependency: Libtorch
http_archive(
    name = "libtorch_archive",
    sha256 = "6b99edc046f37ad37a3b04dc86663895f10c362af09fdd10884f30360d0ba023",
    strip_prefix = "libtorch",
    urls = [
        "https://nexus-repo.corp.prestolabs.io/repository/pytorch-proxy/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcpu.zip",
        "https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.9.0%2Bcpu.zip",
    ],
    build_file_content =
"""
cc_library(
    name = "torch",
    srcs = glob([
        "lib/libtorch.so",
        "lib/libc10.so",
        "lib/libtorch_cpu.so",
        "lib/libgomp-75eea7e8.so.1",
    ]),
    # actually no need linkopts
    linkopts = [
        # "-ltorch",
        # "-lc10",
        # "-ltorch_cpu",
    ],
    defines = [
        "C10_USE_GLOG=1",
        "TORCH_EVAL",
    ],
    hdrs = glob([
        "include/**/*.h"
    ]),
    includes = [
        "include",
        "include/torch/csrc/api/include",
    ],
    visibility = ["//visibility:public"]
)
"""
)

http_file(
  name = "libcatboostmodel_file",
  downloaded_file_path = "libcatboostmodel.so",
  sha256 = "a6d4cfe929304b241b62327f6ac70d0715d3256c50c3ef3fd1ce3d0bbdd1342a",
  urls = ["https://github.com/catboost/catboost/releases/download/v1.2/libcatboostmodel.so"],
)

local_repository(
    name = "interval_draft",
    path = "external/interval_draft",
)

# ---------------------------------------------------------------------------- #
#                                    Prometheus                                #
# ---------------------------------------------------------------------------- #

git_repository(
    name = "com_github_jupp0r_prometheus_cpp",
    commit = "81e208c250748657f1d5dab247e82c4429a931af",
    remote = "https://github.com/jupp0r/prometheus-cpp.git",
)
load("@com_github_jupp0r_prometheus_cpp//bazel:repositories.bzl", "prometheus_cpp_repositories")
prometheus_cpp_repositories()
load("@navi_third_party2//third_party:repositories.bzl", third_party_dependencies = "dependencies")
third_party_dependencies()
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()
